package team.seekers.skill.controller;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import team.seekers.skill.result.Result;
import team.seekers.skill.result.ResultCode;
import team.seekers.skill.common.utils.DesEncryptDecrypt;

/**
 * @author Godc
 * @description
 */
@RequestMapping("/api/desUtils")
@RestController
public class DesEncryptController {
    @GetMapping("/encrypt/{password}")
    public Result Encrypt(@PathVariable String password){
        if(StringUtils.isEmpty(password)){
            return Result.fail(ResultCode.PARAM_IS_BLANK);
        }
        String encryptedStr = "";
        try {
            encryptedStr = DesEncryptDecrypt.getInstance().encrypt(password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.success().data("password",encryptedStr);
    }
    @GetMapping("/decrypt/{password}")
    public Result Decrypt(@PathVariable String password){
        if(StringUtils.isEmpty(password)){
            return Result.fail(ResultCode.PARAM_IS_BLANK);
        }
        String decryptedStr  = "";
        try {
            decryptedStr  = DesEncryptDecrypt.getInstance().decrypt(password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.success().data("password",decryptedStr );
    }
}
